<?php
    //session_start();
    $title = "تعديل بيانات مستخدم";
    include_once '../../Common/View/Header.php'; 
    include_once '../Model/M_EditUser.php'; 
    $user = new User();
    $user->ListUsers();
    $totalUsers = count($user->users);
    $edit = "تعديل";
    $delete = "حذف";
?>
<div id="site_content">
    <div id="content">
        <h1>تعديل بيانات المستخدمين</h1>
        <table class='CSSTableGenerator'>
            <tr>
                <td>المستخدم</td>
                <td>تعديل</td>
                <td>حذف</td>
            </tr>
            <?php
            for($i=0; $i<$totalUsers;$i++){
                ?>
                <tr>
                    <td>
                        <?php
                        printf("%s %s %s",$user->users[$i]["first_name"],$user->users[$i]["father_name"]
                                ,$user->users[$i]["grandfather_name"]);
                        ?>
                    </td>
                    <td>
                         <a href="../View/EditUser.php?username=<?php echo $user->users[$i]["username"];?>"><?php echo $edit; ?></a>
                        
                    </td>
                    <td>
                        <?php
                         if($_SESSION['username']==$user->users[$i]["username"])
                         {
                             echo "حذف";
                         }
                         else
                         {
                             ?>
                            <a href="../Controller/C_EditUser.php?action=delete&username=<?php echo $user->users[$i]["username"];?>"
                           onclick="return confirm('هل تريد حذف المستخدم؟')"><?php echo $delete ?></a>
                            
                            <?php
                         }
                        ?>
                    </td>
                </tr>
            <?php } ?>
        </table>
      </div>
    <?php
            include'../../Common/Model/ErrorMsg.php';
            if(isset($_SESSION['EditUser'])){
                if($_SESSION['EditUser']==true)
                {
                     echo '<br/><br/><center><b><font color=green size=3>'.$corEditUser.'</font></b></center><br/><br/>';
                     unset($_SESSION['EditUser']);                    
                }
                elseif($_SESSION['EditUser']==false)
                {
                     echo '<br/><br/><center><b><font color=red size=3>'.$incorEditUser.'</font></center><br/><br/>';
                     unset($_SESSION['EditUser']);                    
                }
            }
        ?>

    </div>
<?php include_once '../../Common/View/Footer.php'; ?>